<template>
  <div id="toast">
    <transition name="toast">
      <div class="toast_div" v-show="isShow">{{ message }}</div>
    </transition>
  </div>
</template>
<script>
export default {
  data() {
    return {
      isShow: false,
      message: ""
    };
  },
  methods: {
    show(message, delay = 2000) {
      this.isShow = true;
      this.message = message;
      setTimeout(() => {
        this.isShow = false;
      }, delay);
    }
  }
};
</script>
<style scoped>
/**
* 给加入购物车做样式即过渡
*/
.toast_div {
  font-size: 0.8rem;
  text-align: center;
  background-color: rgba(0,0,0,.5);
  border-radius: 0.4rem;
  color: white;
  padding: 8px 12px;
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 999;
}
.toast-enter,
.toast-leave-to {
  opacity: 0;
}
.toast-enter-active {
  transition: opacity 1s;
}
.toast-leave-active {
  transition: opacity 1s;
}
</style>
